import { constant } from 'lodash-es';

/*
 * @Author: Zhang Kai
 * @Date: 2021-11-15 16:33:00
 * @LastEditors: saber
 * @LastEditTime: 2022-06-11 10:34:46
 * @FilePath: /metricsx-standard-ui/src/store/modules/model.ts
 */
const state = {
  drawerVisible: false,
  editDrawerVisible: false,
  id: undefined, // 模型ID
  filterObj: {}, // 模型新建时所需所有参数集合
  modelDetailInfo: {}, // 模型详情信息
  detailById: {}, // 通过ID查询到的layerid等
  createCancel: false, // 从新建第二步取消
  editCancel: false, // 编辑 =》 取消
  schmeaTableData: [], // 库表集合

  tableFieldList: [], // 表格的字段名称
  bindDimensionList: [] // 创建维表时绑定的维度
};

const mutations = {
  toggleDrawerVisible(state: any, st: boolean) {
    state.drawerVisible = st;
  },
  toggleEditDrawerVisible(state: any, st: boolean) {
    state.editDrawerVisible = st;
  },
  setModelId(state: any, id: number) {
    state.id = id;
  },
  setDetailById(state: any, data: any) {
    state.detailById = data;
  },
  setConditionObj(state: any, data: any) {
    // 收集过滤的条件
    state.filterObj = data;
  },
  setModelDetailInfo(state: any, data: any) {
    state.modelDetailInfo = data;
  },
  handleCreateCancel(state: any, data: any) {
    state.createCancel = data;
  },
  handleEditCancel(state: any, data: any) {
    state.editCancel = data;
  },
  saveSchmeaTable(state: any, data: any) {
    state.schmeaTableData = data;
  },

  // 修改当前表格的字段数组
  changeTableList(state: any, data: any) {
    state.tableFieldList = data;
  },

  // 修改当前绑定的维度
  changeDimensionList(state: any, data: any[]) {
    state.bindDimensionList = state.bindDimensionList.concat(data);
  },

  updateDimensionList(state: any, data: any) {
    const index = state.bindDimensionList.findIndex(
      (item: any) => item.dimensionId === data.dimensionId
    );
    state.bindDimensionList[index] = data;
    state.bindDimensionList = [].concat(state.bindDimensionList);
  },
  // 清空当前绑定的维度
  resetDimensionList(state: any) {
    state.bindDimensionList = [];
  }
};

const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
